
this.name = 'lcj'
const person = {
  name: 'hesehuoyan',
  say: () => console.log(this.name),
  sayHello: function () {
    console.log(this.name)
  },
  sayHi: function () {
    setTimeout(function () {
      console.log(this.name)
    }, 500)
  },
  asyncSay: function () {
    setTimeout(() => console.log(this.name), 500)
  }
}

person.say()  //tony
person.sayHello() //tom
person.sayHi() //tony
person.asyncSay()  //tom

// 箭头函数没有constructor，不能当作构造函数使用
let a = () => { };
let b = new a(); //a is not a constructor

// 箭头函数没有arguments,会继承外层arguments
function foo1() {
  setTimeout(() => {
    console.log('arguments', ...arguments)
  }, 1000)
}
foo1(2, 2)

// rest代替arguments
let foo2 = (first, ...rest) => {
  console.log(first, rest) // 1 [2, 3, 4]
};
foo2(1, 2, 3, 4)